package com.fhj.utils;

import java.util.ArrayList;
import java.util.List;

import android.util.Log;

import com.fhj.movie.constant.SearchMode;
import com.fhj.movie.entity.JyjCinemaEntity;
import com.fhj.movie.entity.JyjCircleListEntity;
import com.fhj.movie.entity.JyjDistrictEntity;

public class ListOrder {

	
	public static List<JyjCinemaEntity> list;
	public static List<JyjCinemaEntity> OrderDistrict(
			List<JyjDistrictEntity> listdDistricts,
			List<JyjCinemaEntity> listCinemas) {
		if (listdDistricts != null && listCinemas != null) {
			list = new ArrayList<JyjCinemaEntity>();
			int id = 0;
			for (int i = 0; i < listdDistricts.size(); i++) {
				id = listdDistricts.get(i).getId();
				JyjCinemaEntity cinema = null;
				for (int j = 0; j < listCinemas.size(); j++) {
					cinema = listCinemas.get(j);
					if (id == cinema.getDistrictId()) {
						list.add(cinema);
						listCinemas.remove(j);
					}
				}
			}
			
			int  districts = 0;
			JyjCinemaEntity cinema=null;
			for(int i =0;i<list.size();i++){
				cinema = list.get(i);
				if (districts!=cinema.getDistrictId()) {
					districts=cinema.getDistrictId();
					cinema.setFlags(true);
				}else{
					cinema.setFlags(false);
				}
			}
			
			return list;
		}
		return null;
	}
	
	/**
	 * 对获取的信息根据区域进行圈子的筛选
	 * @param districtId  区域id
	 * @param list	      圈子所有信息
	 * @return				筛选后的圈子信息
	 */
	public static List<JyjCircleListEntity> filtering(int districtId,List<JyjCircleListEntity> list){
		
		List<JyjCircleListEntity>  lists = new ArrayList<JyjCircleListEntity>();
		JyjCircleListEntity entity=null;
		for(int i=0;i<list.size();i++){
			entity = list.get(i);
			if (districtId==entity.getDistrctId()) {
				lists.add(entity);
			}
		}
		return lists;
	}
	
	/**
	 * 根据选中的区域对原始数据进行过滤
	 * @param distructId
	 * @param listCinemas
	 * @return
	 */
	public static List<JyjCinemaEntity> filteringCinema(long distructId,List<JyjCinemaEntity> listCinemas) {
		 List<JyjCinemaEntity> lists = new ArrayList<JyjCinemaEntity>();
		 if (listCinemas!=null) {
			for(int i=0;i<listCinemas.size();i++){
				JyjCinemaEntity entity = listCinemas.get(i);
				if(entity.getDistrictId()==distructId){
					lists.add(entity);
				}
			}
			return lists;
		}
		return null;
	}
	
	/**
	 * 根据不同的类型对数据进行筛选
	 * @param type  筛选条件
	 * @param cinemaEntities   原始数据
	 * @return   筛选后的数据
	 */
	public static List<JyjCinemaEntity> filterByOther(int type,
			List<JyjCinemaEntity> cinemaEntities) {
		List<JyjCinemaEntity> lists = null;
		if (cinemaEntities != null) {
			lists = new ArrayList<JyjCinemaEntity>();
			switch (type) {
			case SearchMode.ALL:
				lists = cinemaEntities;
				break;
			case SearchMode.CONPOU:
				for (int i = 0; i < cinemaEntities.size(); i++) {
					JyjCinemaEntity entity = cinemaEntities.get(i);

					if (entity.getIsCouponSupport() == 1) {
						lists.add(entity);
					}
				}
				break;
			case SearchMode.GROUP_BUY:
				for (int i = 0; i < cinemaEntities.size(); i++) {
					JyjCinemaEntity entity = cinemaEntities.get(i);

					if (entity.getIsGroupBuySupport() == 1) {
						lists.add(entity);
					}
				}
				break;
			case SearchMode.SEAT:
				for (int i = 0; i < cinemaEntities.size(); i++) {
					JyjCinemaEntity entity = cinemaEntities.get(i);

					if (entity.getIsSeatSupport() == 1) {
						lists.add(entity);
					}
				}
				break;
			}
		}
		return lists;
	}
}
